package server.players;


import java.util.ArrayList;
import java.util.List;

import server.locations.Location;

public class PlayerGroup {
	private List<Player> players;
	private Player leader;
	private Location currentLocation = null;
	
	public PlayerGroup(Player player) throws PlayerGroupingException {
		this.players = new ArrayList<Player>();
		this.addPlayer(player);
		this.leader = player;
	}
	
	/**
	 * Adds the Player to this PlayerGroup.
	 * 
	 * @param player
	 * @throws PlayerGroupingException If param player is already part of this group.
	 */
	public void addPlayer(Player player) throws PlayerGroupingException {
		if( !this.players.contains(player) ) {
			this.players.add(player);
			player.addToPlayerGroup(this);
		} else {
			throw new PlayerGroupingException("Trying to add a Player to a "
					+ "PlayerGroup it is already a part of.");
		}
	}
	
	public boolean hasPlayer(Player player) {
		return this.players.contains(player);
	}
	
	/**
	 * Removes the Player from this PlayerGroup.
	 * 
	 * @param player
	 * @throws PlayerGroupingException If param player is not part of this group.
	 */
	public void removePlayer(Player player) throws PlayerGroupingException {
		if( this.players.contains(player) ) {
			this.players.remove(player);
			player.removeFromPlayerGroup(this);
		} else {
			throw new PlayerGroupingException("Trying to remove a Player from a "
					+ "PlayerGroup it is not a part of.");
		}
	}
	
	public Player getLeader() { return this.leader; }
	
	public void setLeader(Player player) {
		this.leader = player;
	}
	
	public Location getLocation() { return this.currentLocation; }
	
	public void setLocation(Location loc) {
		this.currentLocation = loc;
	}
}
